# -*- coding: utf-8 -*-

def BinaryResearch(arr, key):
    left = 0
    right = len(arr)
    while left <= right:
        mid = (right - left) // 2
        if arr[left+mid] < key:
            left = left+mid+1
        elif arr[left+mid] > key:
            right = left+mid-1
        else:
            return left+mid
    return -1
s1 = [0,2,3,5,8,9,12,30,40,50,55]
key = 55
r = BinaryResearch(s1, key)
if r == -1:
    print('列表里没有%d元素' % (key))
else:
    print('在列表里找到元素%d，其下标为%d' %(key, r))


